#include <iostream>
#include <queue>

int main()
{
    std::string quatks;
    std::cin >> quatks;

    int q_cnt = 0;
    int u_cnt = 0;
    int a_cnt = 0;
    int c_cnt = 0;
    int k_cnt = 0;

    int i = 0;
    std::queue<int> q_que;
    int count[1001] = {0};
    int max_val = 0;

    while (i < quatks.size())
    {
        count[i + 1] = count[i];
        if (quatks[i] == 'q')
        {
            q_que.push(i);
            q_cnt++;
        }
        else if (quatks[i] == 'u' && q_cnt > u_cnt)
        {
            u_cnt++;
        }
        else if (quatks[i] == 'a' && u_cnt > a_cnt)
        {
            a_cnt++;
        }
        else if (quatks[i] == 'c' && a_cnt > c_cnt)
        {
            c_cnt++;
        }
        else if (quatks[i] == 'k' && c_cnt > k_cnt)
        {
            k_cnt++;
            int idx = q_que.front();
            q_que.pop();
            count[i + 1]++;
            max_val = std::max(max_val, count[i + 1] - count[idx]);
        }
        else if (quatks[i] != 'q' || quatks[i] != 'u' || quatks[i] != 'a' || quatks[i] != 'c' || quatks[i] != 'k')
        {
            break;
        }

        i++;
    }

    if (max_val == 0)
        std::cout << -1 << std::endl;
    else
        std::cout << max_val << std::endl;

    return 0;
}